package java10;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

public class C3P0Test02 {
    public static void main(String[] args) {
        //获取DataSource
        DataSource ds = new ComboPooledDataSource();
        //获取连接
        for(int i = 1; i <= 11; i++){
            Connection conn = null;
            try {
                conn = ds.getConnection();
                System.out.println(i + ":" + conn);
                if(i == 5){
                    conn.close();//归还连接到连接池中
                }
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
            }
        }
}
